package org.example.controller;

import org.example.GetConnection;
import org.example.info.Record;
import org.example.info.Result;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

//查看记录
@RestController
@CrossOrigin(origins = "*")
public class RecordController {
    private Connection connection = new GetConnection().GetConnection();
    private PreparedStatement statement;
    private ResultSet resultSet;
    @GetMapping("/record")
    public Result<?> getRecord() throws SQLException {
        statement = connection.prepareStatement("select * from record");
        resultSet = statement.executeQuery();
        List<Record> recordList = new ArrayList<>();
        while (resultSet.next()) {
            recordList.add(new Record(resultSet.getInt("id"), resultSet.getInt("bookID"),resultSet.getInt("userID"),resultSet.getTime("time"),resultSet.getInt("type")));
        }
        return Result.success(recordList);
    }

}
